JavaSctipt 與瀏覽器的溝通


Posted by YongChenSu on 2020-12-08

什麼是 DOM?

文件物件模型 (DOM, document object model),瀏覽器提供了一個橋樑,可用 JS 改變畫面上的東西。

選到想要的元素

  • getElementById
  • getElementsByTagName
  • getElementsByClassName
  • querySelector
  • querySelectorAll

改變 css

  • classList.add()
  • classList.remove()
  • classList.toggle()

改變內容

  • innerText
  • innerHTML
  • outerHTML:可用來改變標籤形式

新增、刪除元素

  • element.removeChild(document.querySelector('a'))

  • element.appendChild(item)

    • const item = document.createElement('div')
    • const item2 = document.createTextNode('132')

#程式導師實驗計畫第四期 #前端







Related Posts

【單元測試的藝術】Chap 10: 遺留程式碼

【單元測試的藝術】Chap 10: 遺留程式碼

[Python] 好用的 concurrent.futures is a good way to speed up your function

[Python] 好用的 concurrent.futures is a good way to speed up your function

筆記、[FE101] 前端基礎 盒模型與定位

筆記、[FE101] 前端基礎 盒模型與定位


Comments